package com.yonyou.pmclouds.plantemplate.processor;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.plantemplate.entity.ScheduleTemplateItemVO;
import com.yonyou.pmclouds.plantemplate.entity.ScheduleTemplateVO;
import com.yonyou.pmclouds.plantemplate.rmiitf.IScheduleTemplateItemProcessor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @Description: 计划模板任务项必填项校验
 * @Author: zhangzhonghao
 * @Date: 2020-03-06
 */

@Component
public class ScheduleTemplateItemRequiredCheckProcessor implements IScheduleTemplateItemProcessor {

    @Override
    public void process(ScheduleTemplateVO templateVO, ScheduleTemplateItemVO rootParentItemVO, ScheduleTemplateItemVO parentItemVO,
                        ScheduleTemplateItemVO childItemVO) throws BusinessException {
        if(childItemVO != null){
            itemCheck(childItemVO);
        }

    }

    private void itemCheck(ScheduleTemplateItemVO itemVO) throws BusinessException {
        if (StringUtils.isBlank(itemVO.getName())) {
            throw new BusinessException("计划名称不能为空");
        } else if (itemVO.getName().length() > 50) {
            throw new BusinessException("计划名称长度不能超过50字");
        }
    }
}
